package com.project.controller;

import com.framework.core.result.APIListResponse;
import com.framework.core.result.APIObjResponse;
import com.project.base.BaseController;
import com.project.biz.CmsRecoveryTypeBiz;
import com.project.common.model.UserInfo;
import com.project.entity.CmsRecoveryType;
import com.project.pojo.model.AddProductModel;
import com.project.pojo.model.AddRecoveryTypeModel;
import com.project.pojo.model.UpdateProductModel;
import com.project.pojo.model.UpdateRecoveryTypeModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 回收品类
 * @Author: zhuchi
 * @CreateDate: 2020/11/13 20:55
 * @Version: 1.0
 */
@Api(value = "CmsRecoveryTypeController", description = "回收品类")
@RestController
@RequestMapping("/recoveryType")
@Slf4j
public class CmsRecoveryTypeController extends BaseController {

    /**
     * 回收品类业务层接口类
     */
    @Autowired
    private CmsRecoveryTypeBiz recoveryTypeBiz;

    /**
     * 获取所有回收品类
     * @return
     */
    @ApiOperation(value = "获取所有回收品类", httpMethod = "GET")
    @GetMapping(value = "/getAllRecoveryType")
    public APIListResponse<CmsRecoveryType> getAllRecoveryType(){
        List<CmsRecoveryType> result = this.recoveryTypeBiz.getAllRecoveryType();

        return APIListResponse.success("查询成功", result);
    }

    /**
     * 获取回收品类详情
     * @param recoveryTypeId
     * @return
     */
    @ApiOperation(value = "获取回收品类详情，参数{recoveryTypeId ：回收品类ID }", httpMethod = "GET")
    @GetMapping(value = "/getRecoveryTypeDetail")
    public APIObjResponse<CmsRecoveryType> addRecoveryType(@RequestParam("recoveryTypeId") Long recoveryTypeId){
        CmsRecoveryType recoveryType = this.recoveryTypeBiz.getById(recoveryTypeId);
        return APIObjResponse.success("操作成功", recoveryType);
    }

    /**
     * 添加回收品类
     * @param addRecoveryTypeModel
     * @return
     */
    @ApiOperation(value = "后台-添加回收品类", httpMethod = "POST")
    @PostMapping(value = "/addRecoveryType")
    public APIObjResponse<Integer> addRecoveryType(@Validated @RequestBody AddRecoveryTypeModel addRecoveryTypeModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryTypeBiz.addRecoveryType(addRecoveryTypeModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 修改回收品类
     * @param updateRecoveryTypeModel
     * @return
     */
    @ApiOperation(value = "后台-修改回收品类", httpMethod = "POST")
    @PostMapping(value = "/updateRecoveryType")
    public APIObjResponse<Integer> updateRecoveryType(@Validated @RequestBody UpdateRecoveryTypeModel updateRecoveryTypeModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryTypeBiz.updateRecoveryType(updateRecoveryTypeModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 删除回收品类
     * @param recoveryTypeId
     * @return
     */
    @ApiOperation(value = "后台-删除回收品类", httpMethod = "GET")
    @GetMapping(value = "/delRecoveryType")
    public APIObjResponse<Integer> delRecoveryType(@RequestParam("recoveryTypeId") Long recoveryTypeId){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryTypeBiz.delRecoveryType(recoveryTypeId, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

}
